﻿using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using System.Data.OleDb;

namespace Web.Pages.QuShui.DiXiaS.ShouFeiGL
{
    public partial class HuiGuanTFSP : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtGrid
        {
            get
            {
                return ViewState["dtGrid"] as DataTable;
            }
            set
            {
                ViewState["dtGrid"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        BLL.SqlHelper _SplHelper = new BLL.SqlHelper();

        /// <summary>
        /// 管理部门
        /// </summary>
        QS_JX_BUMENXXBLL GLBM = new QS_JX_BUMENXXBLL();

        /// <summary>
        /// 回灌退费
        /// </summary>
        QS_SF_HUIGUANTF HGTF = new QS_SF_HUIGUANTF();

        /// <summary>
        /// 回灌退费BLL
        /// </summary>
        QS_SF_HUIGUANTFBLL HGTFBLL = new QS_SF_HUIGUANTFBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
                LoadGridData();
            }
            gvList.DataSource = dtGrid;
            gvList.DataBind();

        }

        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            LoadGridData();
        }

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            string sUID = hdCollection.Get("ID").ToString();
            string msg = "";
            if (e.Parameter == "add")
            {
                try
                {
                    int iVal = Convert.ToInt32(hdCollection.Get("ID" + sUID));
                    _SplHelper.P_DXSSF_HGTF_SP_ADD(0, sUID, iVal);
                }
                catch (Exception) { }
            }
            else if (e.Parameter == "cancel")
            {
                try
                {
                    int iVal = Convert.ToInt32(hdCollection.Get("ID" + sUID));
                    _SplHelper.P_DXSSF_HGTF_SP_ADD(-1, sUID, iVal);
                }
                catch (Exception) { }
            }

            else if (e.Parameter == "save")
            {
            }
            e.Result = e.Parameter + "|0|" + msg;
        }

        protected void gvList_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            ASPxTextBox txtSQL = gvList.FindRowCellTemplateControl(1,
                (GridViewDataColumn)(((GridViewBandColumn)(gvList.Columns["SQL"])).Columns[0]), "txtSQL") as ASPxTextBox;
            LoadGridData();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            int wtype = BusinessTool.WType;
            //gvList.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            int water_y_m = Convert.ToInt32(BusinessTool.GetSLYMorZWNY(1, wtype));
            for (int i = DateTime.Now.Year - 10; i <= DateTime.Now.Year; i++)
            {
                cmbYear.Items.Add(i.ToString(), i.ToString());
            }
            cmbYear.Value = water_y_m / 100;
        }

        /// <summary>
        /// 加载查询数据
        /// </summary>
        private void LoadGridData()
        {
            try
            {
                int y = Convert.ToInt32(cmbYear.Value);
                int iWorkT = Convert.ToInt32(rblWorktype.SelectedItem.Value);
                dtGrid = _SplHelper.P_DXSSF_HGTF_SP_LIST(0, y, 0, txtYonghuh.Text, iWorkT).Tables[0];
                gvList.DataSource = dtGrid;
                gvList.DataBind();
                zjl.Text = "共" + gvList.VisibleRowCount + "条";
            }
            catch (Exception) { }
        }

       
        #endregion

    }
}